//JavaScript Framework 2.0 Code
try{
Type.registerNamespace('com.yonyou.ncmm_pac_pda.PoArrivalOrderController');
com.yonyou.ncmm_pac_pda.PoArrivalOrderController = function() {
    com.yonyou.ncmm_pac_pda.PoArrivalOrderController.initializeBase(this);
    this.initialize();
}
function com$yonyou$ncmm_pac_pda$PoArrivalOrderController$initialize(){
    //you can programing by $ctx API
    //get the context data through $ctx.get()
    //set the context data through $ctx.push(json)
    //set the field of the context through $ctx.put(fieldName, fieldValue)
    //get the parameter of the context through $ctx.param(parameterName)
    //Demo Code:
    //    var str = $ctx.getString();      //获取当前Context对应的字符串
    //    alert($ctx.getString())          //alert当前Context对应的字符串
    //    var json = $ctx.getJSONObject(); //获取当前Context，返回值为json
    //    json["x"] = "a";        //为当前json增加字段
    //    json["y"] = [];           //为当前json增加数组
    //    $ctx.push(json);            //设置context，并自动调用数据绑定
    //    
    //    put方法需手动调用databind()
    //    var x = $ctx.get("x");    //获取x字段值
    //    $ctx.put("x", "b");     //设置x字段值
    //    $ctx.put("x", "b");     //设置x字段值
    //    $ctx.databind();            //调用数据绑定才能将修改的字段绑定到控件上
    //    var p1 = $param.getString("p1");   //获取参数p2的值，返回一个字符串
    //    var p2 = $param.getJSONObject("p2");   //获取参数p3的值，返回一个JSON对象
    //    var p3 = $param.getJSONArray("p3");   //获取参数p1的值，返回一个数组
    
    //your initialize code below...
    
}
    
function com$yonyou$ncmm_pac_pda$PoArrivalOrderController$evaljs(js){
    eval(js)
}
var Code="";
var jh="";
function com$yonyou$ncmm_pac_pda$PoArrivalOrderController$button2_onclick(sender, args){
	var lph = $id("textbox0").get("value");
	var materialcode = $id("label6").get("value");
	if($cache.read("CodeRule")!=""||$cache.read("CodeRule")!="undefined"){
		if($cache.read("CodeRule")=="ML"){
			if($id("textbox2").get("value")==""||lph==""||materialcode==""){
				$alert("物料内容不完整，请补齐后再生成条码");
				return;
			}
			//var json = MMFlowSnUtil.getFlowSn(vbillcode,lph);
			var lsh = $id("textbox2").get("value");//json.substring(lph.length,json.length);
			var weight = $id("textbox2").get("value");
			if(lsh==""||lph==""||weight==""||materialcode==""){
				$alert("物料内容不完整，请补齐后再生成条码");
				return;
			}else{
				$id("label22").set("value",lph+lsh);
				$id("label21").set("value",lsh);
				while(jh==$id("label22").get("value")){
				}
				jh = $id("label22").get("value");
				//$alert(jh);
				Code = "ML;"+ materialcode+";"+lph+";"+jh+";"+weight;
				//$alert(Code);
			}
		}else if($cache.read("CodeRule")=="FM"){
			if(lph==""||materialcode==""){
				$alert("物料内容不完整，请补齐后再生成条码");
				return;
			}else{
				Code = "FM;"+ materialcode+";"+lph;
				//$alert(Code);
			}
		}else{
			$alert("条码规则未定义");
			return;
		}
		$id("label2").set("value",Code);
	}else{
		$alert("条码规则未设置,请选择");	
	}
}
var QRCodeConf={"QR_l":"670","QR_h":"90","QR_v":"150","QR_e":"8","T_h":"90","T_v":"450"};
function readConf(){
	if($cache.read("conf")!=undefined){
		QRCodeConf = $cache.read("conf");
	}
}
function com$yonyou$ncmm_pac_pda$PoArrivalOrderController$button4_onclick(sender, args){
	if(Code!=""){
		if($cache.read("conf")!=undefined&&$cache.read("conf")!=""){
			var json = {};
			//$alert($cache.read("conf"));
			json.conf = $cache.read("conf");
			json.Code = Code;
			json.name = $id("label8").get("value");
			json.spec = $id("label10").get("value");
			json.type = $id("label12").get("value");
			json.vbillcode = $id("textbox0").get("value");
			json.weight = $id("textbox2").get("value")+unit;
			json.jh = $id("label22").get("value");
			json.CodeRule = $cache.read("CodeRule");
			//$alert(json);
			$service.call("DXYBTPrinterConnectService.send", {"data":json}, "true");
			//$alert(res);
		}else{
			$alert("二维码样式未设置,无法打印！");
		}
	}else{
		$alert("条码内容为空,无法打印！");
	}
}
var index;
var data={};
var unit;
var vbillcode;
var size;
function com$yonyou$ncmm_pac_pda$PoArrivalOrderController$viewPage0_onload(sender, args){
	if($cache.read("conf")==undefined||$cache.read("conf")==""){
		$cache.write("conf",QRCodeConf);
	}
	index = $param.getString("index");
	size = $param.getString("size");
	//$alert("接收到的index="+index);
	//var listdata = $param.getString("data");
	var listdata = $param.getJSONObject("data");
	data.data = listdata;
	//$alert($jsonToString(data));
	var Material = data["data"][index];
	$id("label6").set("value",Material["materialcode"]);
	$id("label8").set("value",Material["materialname"]);
	$id("label10").set("value",Material["materialspec"]);
	$id("label12").set("value",Material["materialtype"]);
	unit = Material["cunitidname"];
	vbillcode = Material["vbillcode"];
	$id("label4").set("value",$cache.read("CodeRule"));
}
function com$yonyou$ncmm_pac_pda$PoArrivalOrderController$button1_onclick(sender, args){
	readConf();
	//$alert(QRCodeConf);
	$view.open({
        "viewid" : "com.yonyou.ncmm_pac_pda.TwoDCodeConfig",//目标页面（首字母大写）全名
        "isKeep" : "true",
        "conf" : QRCodeConf,
        "callback" : "myCallBack()"//关闭viewid页面后，执行的回调方法
    })
}
function myCallBack(){
	QRCodeConf = $param.getString("confdata");
	//$alert(QRCodeConf);
	$cache.write("conf",QRCodeConf);
}
function com$yonyou$ncmm_pac_pda$PoArrivalOrderController$button0_onclick(sender, args){
	$view.close({
            "resultCode": "15",//当resultCode为15时，可以响应父页面的callback
        });
}
function com$yonyou$ncmm_pac_pda$PoArrivalOrderController$button5_onclick(sender, args){
    var newDialog = $window.showModalDialog({
    	"dialogId" : "com.yonyou.ncmm_pac_pda.CodeRuleSelect",
    	"animation-type" : "center", //left|bottom|top|right|center弹出的起始方向
    	"arguments" : {
    	},
    	"features" : {
        	"dialogLeft" : 100,
        	"dialogTop" : 150,
        	"dialogWidth" : 200, //如设置此参数则弹窗页面设置大小无效
        	"dialogHeight" : 300 //如设置此参数则弹窗页面设置大小无效
    	},
    	callback : "RuleCallBack()"
	});
}
function RuleCallBack(){
	if($param.getString("CodeRule")!=""){
		var CodeRule = $param.getString("CodeRule");
		$cache.write("CodeRule",CodeRule);
		$id("label4").set("value",CodeRule);
		$id("label22").set("value","");
		$id("label21").set("value","");
		$id("textbox2").set("value","");
		$id("label2").set("value","");
	}
}
function com$yonyou$ncmm_pac_pda$PoArrivalOrderController$button3_onclick(sender, args){
	index++;
	if(index==size){
		index = 0;
	}
	var Material = data["data"][index];
	$id("label6").set("value",Material["materialcode"]);
	$id("label8").set("value",Material["materialname"]);
	$id("label10").set("value",Material["materialspec"]);
	$id("label12").set("value",Material["materialtype"]);
	$id("textbox0").set("value","");
	$id("textbox2").set("value","");
	$id("label21").set("value","");
	$id("label2").set("value","");
	$id("label22").set("value","");
	unit = Material["cunitidname"];
	vbillcode = Material["vbillcode"];
}
com.yonyou.ncmm_pac_pda.PoArrivalOrderController.prototype = {
    button3_onclick : com$yonyou$ncmm_pac_pda$PoArrivalOrderController$button3_onclick,
    button5_onclick : com$yonyou$ncmm_pac_pda$PoArrivalOrderController$button5_onclick,
    button0_onclick : com$yonyou$ncmm_pac_pda$PoArrivalOrderController$button0_onclick,
    button1_onclick : com$yonyou$ncmm_pac_pda$PoArrivalOrderController$button1_onclick,
    viewPage0_onload : com$yonyou$ncmm_pac_pda$PoArrivalOrderController$viewPage0_onload,
    button4_onclick : com$yonyou$ncmm_pac_pda$PoArrivalOrderController$button4_onclick,
    button2_onclick : com$yonyou$ncmm_pac_pda$PoArrivalOrderController$button2_onclick,
    initialize : com$yonyou$ncmm_pac_pda$PoArrivalOrderController$initialize,
    evaljs : com$yonyou$ncmm_pac_pda$PoArrivalOrderController$evaljs
};
com.yonyou.ncmm_pac_pda.PoArrivalOrderController.registerClass('com.yonyou.ncmm_pac_pda.PoArrivalOrderController',UMP.UI.Mvc.Controller);
}catch(e){$e(e);}
